package bag

import (
	"fmt"
	"server/game/item"
)

func EnUseItem(UserId string, itemTmpId int, Quantity int) ([]item.Item, error) {
	backLogic := NewBackpack(UserId, Bagsiz)
	item, check := backLogic.GetItem(itemTmpId)
	if !check || item.Quantity <= 0 || item.Quantity < Quantity {
		return nil, fmt.Errorf("物品数量不够")
	}
	err := backLogic.UseItem(itemTmpId, Quantity)
	if err != nil {
		return nil, err
	}
	return backLogic.ListItems(), nil
}
func EnInitUserItem(UserId string) {
	//chaoPiaoTmp := cfg.ConfigData.TbItem.Get(101)
	logic := NewBackpack(UserId, Bagsiz)
	logic.AddItem(UserId, 101, 1000)
	logic.AddItem(UserId, 102, 50)
	logic.AddItem(UserId, 140001, 50)
}

func EnAddItem(UserId string, itemTmpId int, Quantity int) ([]item.Item, error) {
	bagLogic := NewBackpack(UserId, Bagsiz)
	bagLogic.AddItem(UserId, itemTmpId, Quantity)
	return bagLogic.ListItems(), nil
}
func EnGetUserItem(UserId string) ([]item.Item, error) {
	backLogic := NewBackpack(UserId, Bagsiz)
	return backLogic.ListItems(), nil
}
